#pragma once
#include "cocos2d.h"
#include <typeinfo>
#include <string>
#include <cstddef>

namespace NsClasses
{
    class Utility
    {
    public:
        template<typename T0, typename T1> static
        T0 *As(T1 *p)
        {
            return dynamic_cast<T0 *>(p);
        }
    public:
        template<typename T0, typename T1> static
        T0 *Of(T1 *p)
        {
            T0 *t = As<T0>(p);
            CCASSERT(t != nullptr, (std::string("The Type Of p is not ") + typeid(T0).name()).c_str());
            return t;
        }
    public:
        template<class _Ty> static
            _Ty *AddressOf(_Ty& _Val) throw ()
        {	// return address of _Val
            return (reinterpret_cast<_Ty *>(
                (&const_cast<char&>(
                reinterpret_cast<const volatile char&>(_Val)))));
        }
    public:
        template<typename T0, typename T1> static
        bool IsAddressEqual(T0 t0, T1 t1) throw ()
        {
            return reinterpret_cast<size_t>(AddressOf(t0)) == reinterpret_cast<size_t>(AddressOf(t1));
        }
    }; 
}